<template>
	<view class="cu-bar fixed" :style="opacity==0?'box-shadow: none':''">
		<view class="cu-custom" :style="[{height:CustomBar + 'px'}]">
			<view class="cu-bar fixed" :style="style" :class="[bgImage!=''?'none-bg text-white bg-img':'']">
				<view class="action" @tap="BackPage" v-if="isBack">
					<text class="cuIcon-back navBack" :style="[{fontSize: 28+'rpx'},{background:'rgba(0,0,0,'+fontColor?0:iconOpcity+')'},{color: fontColorBack}]"></text>
					<slot name="backText"></slot>
				</view>
				<view class="content " :style="[{top:StatusBar + 'px'},{opacity:opacity},{color:fontColor}]">
					<slot name="content"></slot>
				</view>
				<slot name="right"></slot>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				StatusBar: this.StatusBar,
				CustomBar: this.CustomBar,
				fontColorBack: '#fff'
			};
		},
		name: 'cu-custom',
		computed: {
			style() {
				var StatusBar = this.StatusBar;
				var CustomBar = this.CustomBar;
				var bgImage = this.bgImage;
				var bgColor = this.bgColor;
				// 自定义
				var opacity = this.opacity;
				if (opacity != '0') {
					var style = `height:${CustomBar}px;padding-top:${StatusBar}px;background:rgba(${bgColor},${opacity});`;
				} else {
					var style =
						`height:${CustomBar}px;padding-top:${StatusBar}px;background:rgba(${bgColor},${opacity});box-shadow: none;`;
				}
				if (this.bgImage) {
					style = `${style}background-image:url(${bgImage});`;
				}
				// 
				if(this.fontColor){
					if(opacity!=0){
						this.fontColorBack = '#333'
					}else{
						this.fontColorBack = '#fff'
					}
				}
				return style
			}
		},
		props: {
			fontColor:{
				type: String,
				default: '#fff'
			},
			bgColor: {
				type: String,
				default: ''
			},
			iconOpcity: {
				type: String,
				default: ''
			},
			isBack: {
				type: [Boolean, String],
				default: false
			},
			rgbVal: {
				type: String,
				default: ''
			},
			opacity: {
				type: String,
				default: ''
			},
			bgImage: {
				type: String,
				default: ''
			},
		},
		methods: {
			BackPage() {
				var length = getCurrentPages().length
				if(length==1){
					uni.switchTab({
						url:'/pages/tabBar/home'
					})
					return
				}
				uni.navigateBack({
					delta: 1
				});
			}
		}
	}
</script>

<style>
	.navBack {
		color: #fff;
		border-radius: 100%;
		width: 45rpx;
		height: 45rpx;
		text-align: center;
		line-height: 45rpx;

	}
</style>
